﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using FTchina;

public partial class smstask_LoginCheck : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        ChekLogin();
    }



   /// <summary>
   /// 检查客户端登陆，只有成功才返回32位SenderID
   /// </summary>
    private void ChekLogin()
    {
        string ReturnMsg = string.Empty;
        string username = FTchina.basic.SafeRequest(Request["username"]);
        string userpsw = FTchina.basic.SafeRequest(Request["userpsw"]);

        string GetSql = "select top 1 * from SenderList where sendername ='{0}' and psw='{1}' ";

        if (shujuku.testread(string.Format(GetSql, username, userpsw)))
        {
            using (DataTable dt = shujuku.GetDataTable(string.Format(GetSql, username, userpsw)))
            {

                switch (dt.Rows[0]["state"].ToString())
                {
                    case "0":
                        ReturnMsg = dt.Rows[0]["senderID"].ToString();
                        break;
                    case "1":
                        ReturnMsg = "禁止登陆";
                        break;
                    case "2":
                        ReturnMsg = "禁止发送短信";
                        break;
                    default:
                        ReturnMsg = "登陆失败";
                        break;
                }
            }
        }
        else
        {
            ReturnMsg = "用户名或者密码不正确";
        }
        FTchina.basic.Log(username + FTchina.basic.GetUserIp() + "登录" + ReturnMsg);

        #region 写入登录记录表
        FTchina.Models.Login_Log mLogin_Log = new FTchina.Models.Login_Log();
        mLogin_Log.Id =0;
        mLogin_Log.Uname = username;
        mLogin_Log.Loginip =FTchina.basic.GetUserIp();
        mLogin_Log.Logindate = DateTime.Now;
        mLogin_Log.Version = FTchina.basic.SafeRequest(Request["v"]);
        mLogin_Log.Utype = FTchina.basic.SafeRequest(Request["type"]);
        mLogin_Log.Result = ReturnMsg;
      FTchina.BLL.Login_LogManager.AddLogin_Log(mLogin_Log);
        #endregion

        Response.Write(ReturnMsg);
    }
}